package setting

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	pb "gitee.com/liuxuezhan/ar-platform/rpc-client/safeBoxClient/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetSafeConfigLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 获取保险箱配置信息
func NewGetSafeConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSafeConfigLogic {
	return &GetSafeConfigLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetSafeConfigLogic) GetSafeConfig(req *types.GetSafeConfigInfoReq) (resp *types.GetSafeConfigInfoResp, err error) {
	// RPC请求
	out, err := l.svcCtx.SafeBoxRpcService.Setting.SafeConfigInfo(l.ctx, &pb.SafeConfigInfoRequest{})
	if err != nil {
		return nil, err
	}
	// 处理返回数据
	resp = &types.GetSafeConfigInfoResp{
		Quota: out.Quota,
		Rate:  out.Rate,
	}
	return
}
